<?php
/**
 * User: 昊天||597767865@qq.com
 * Date: 2019/8/29
 * Time: 11:41
 */
namespace backend\controllers;
use backend\models\Set;

class SetController extends BaseController
{
    public function actionIndex()
    {
        $set = Set::find()->asArray()->all();
        $type = array_unique(array_column($set,'type'));
        $setting = [];
        foreach ($type as $val){
            $setting[$val] = Set::find()->where(['type'=>$val])->orderBy('sort desc,id desc')->asArray()->all();
        }
        return $this->render('index',compact('type','setting'));
    }

    /**
     * 设置修改
     */
    public function actionEdit()
    {
        $id = intval(input('id'));
        $val = input('val');
        $model = Set::findOne($id);
        $model->val = $val;
        if($model->save()){
            $this->json(200,'修改成功');
        }
        $this->json(100,array_values($model->getFirstErrors())[0]);
    }



}
